package cn.com.lyj6851.auth.endpoint;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.com.lyj6851.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 登出接口
 **/
@RestController
@FrameworkEndpoint
@Api(tags = "登出接口")
public class TokenRevokeEndpoint {

    @Autowired
    @Qualifier("consumerTokenServices")
    private ConsumerTokenServices tokenServices;


	@DeleteMapping("/oauth/token")
    @ApiOperation("退出登录")
    public Result<?> deleteAccessToken(@RequestParam("access_token") String accessToken){
        if(tokenServices.revokeToken(accessToken)) {
        	return Result.ok("注销成功");
        }else {
        	return Result.failure(500, "注销失败");
        }
        
    }

}
